package com.android.jump;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;

public class HighScore
{
    private GameView mView = null;
    private Paint mPaint = null;
    private Bitmap mBG = null;
    private PrintNum mPN = null;
    private Bitmap gold = null;
    private Bitmap sliver = null;
    private Bitmap brone = null;
    
    public HighScore(GameView view, Bitmap bg, Bitmap nums[], Bitmap nGold, Bitmap nSliver, Bitmap nBrone) {
        mView = view;
        mPaint = new Paint();
        mPaint.setColor(Color.RED);
        mBG = bg;
        mPN = new PrintNum(nums);
        gold = nGold;
        sliver = nSliver;
        brone = nBrone;
    }
    
    public void doDraw(Canvas canvas) {
        canvas.drawBitmap(mBG, 0, 0, mPaint);
        //canvas.drawText("HighScore", 10, 10, mPaint);
        FileInputStream fos;
        try
        {
            fos = mView.getContext().openFileInput("hs");
            BufferedReader fbr = new BufferedReader(new InputStreamReader(fos));
            String str = null;
            try
            {
                int i = 0;
                while ((str = fbr.readLine()) != null) {
                    //canvas.drawText(str, 20, 30 + i++ * 20, mPaint);
                    mPN.doDraw(canvas, Integer.parseInt(str), 100, 140 + i++ * 50);
                }
                if (i > 0) {
                    canvas.drawBitmap(gold, 40, 140, null);
                }
                if (i > 1 ) {
                    canvas.drawBitmap(sliver, 40, 190, null);
                }
                if (i > 2) {
                    canvas.drawBitmap(brone, 40, 240, null);
                }
                fbr.close();
            }
            catch (IOException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        catch (FileNotFoundException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
